import 'package:get/get.dart';
import 'package:honeypotflutter/modules/cabinet/pages/cabinet_form_deliver/view.dart';
import 'package:honeypotflutter/modules/cabinet/pages/cabinet_form_earnings/view.dart';
import 'package:honeypotflutter/modules/cabinet/views/cabinet_form_bottom.dart';
import 'package:honeypotflutter/public/public_alert.dart';
import 'package:honeypotflutter/public/public_total.dart';
import 'package:honeypotflutter/publicBussine/bussine_date.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';

class CabinetFormLogic extends GetxController {
  RxString forms = RxString("");
  RxString startTime = RxString("");
  RxString endTime = RxString("");
  int _selectIndex = -1;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    BussineSelectDateModel dateModel = MGBussineDate.calculateDate();
    startTime.value = dateModel.startTime;
    endTime.value = dateModel.endTime;
  }

  /*
  * 时间弹框
  * */
  showBottomDate() async {
    showCupertinoModalBottomSheet(
      context: Get.context!,
      builder: (context) => CabinetFormBottom(
        monthResult: (String start, String end) {
          startTime.value = start;
          endTime.value = end;
        },
        customResult: (String start, String end) {
          startTime.value = start;
          endTime.value = end;
        },
      ),
    );
  }

  /*
  * 选择报表
  * */
  selectForm() async {
    HLAlert.showConfirmation(
      title: "选择报表类型",
      menuList: ["柜机投递报表", "柜机收益报表"],
      action: (int index, String text) {
        forms.value = text;
        _selectIndex = index;
      },
    );
  }

  /*
  * 查询
  * */
  queryAction() {
    if (forms.value.isEmpty) {
      HLTotal.total("请选择报表类型");
      return;
    }
    if (_selectIndex == 0) {
      Get.to(
        CabinetFormDeliverPage(),
        arguments: {"startTime": startTime.value, "endTime": endTime.value},
      );
      return;
    }
    Get.to(
      CabinetFormEarningsPage(),
      arguments: {"startTime": startTime.value, "endTime": endTime.value},
    );
  }
}
